<?php

/**
 * 发现列表页
 * ============================================================================
 * $Author: 王海龙 $
 * $Id: tvd_list.php 2015-09-03 王海龙 $
*/

require(dirname(__FILE__) . '/includes/init.php');
include_once(ROOT_PATH . '/includes/funTvd.php');
@ini_set('display_errors',        1);

assign_template();

/* AJAX返回搜索结果 */
if (!empty($_REQUEST['isAjax'])) {

    $tvdList = getTvdList();
    $smarty->assign('tvdList', $tvdList);
    if (!empty($tvdList)) {
        $result['error'] = 0;
        $result['count'] = count($tvdList);
        $result['content'] = $smarty->fetch('tvd/tvdList.lbi');
    } else {
        $result['error'] = 1;
        $result['message'] = '已全部加载！END';
    }
    echo JSON()->encode($result);
    exit();
}

/* 搜索词、品牌、分类 */
$q   = !empty($_REQUEST['q']) ? htmlspecialchars(trim($_REQUEST['q'])) : '';
$c   = !empty($_REQUEST['c']) ? intval($_REQUEST['c']) : 0;
$smarty->assign('c', $c);
$smarty->assign('q', $q);

/* 获取一级分类 */
$catList = getTvdCatChildren();
foreach ($catList as $key => $value) {
    /* 获取二级分类 */
    $value['children'] = getTvdCatChildren($value['cat_id']);
    $catList[$key] = $value;
}
$smarty->assign('catList', $catList); // 显示分类

$smarty->assign('page_title',      htmlspecialchars($_CFG['shop_title'])); // 首页页面标题
$smarty->assign('keywords',        htmlspecialchars($_CFG['shop_keywords'])); // 首页SEO网站关键词
$smarty->assign('description',     htmlspecialchars($_CFG['shop_desc'])); // 首页SEO网站描述
$smarty->assign('footType', true); // 是否显示导航
$smarty->assign('nav', true); // 是否显示导航
$smarty->display('tvd/list.dwt');
